package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.GetChildSelectionConditionListBean;
import com.shop2cn.iapi.agentproducts.parameter.SaveSelectionConditionBean;
import com.shop2cn.iapi.agentproducts.service.GetChildSelectionConditionListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*查询为下级设置的选货筛选类型列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetChildSelectionConditionList{
	private static GetChildSelectionConditionListBean getchildselectionconditionlistBean;
	private static GetChildSelectionConditionListCall getchildselectionconditionlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询为下级设置的选货筛选类型列表Test");
	}

	@Before
	public void caseUp() {
		getchildselectionconditionlistBean=new GetChildSelectionConditionListBean();
		getchildselectionconditionlistCall=new GetChildSelectionConditionListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getchildselectionconditionlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private int MchId=501163178;
	private int AgentId = 501163179;
	private int AgentId1 = 501163181;
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetChildSelectionConditionList_001() {
		Logger.start(true,"代理1设置规则，代理2未设置，成功");
		try {
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			getchildselectionconditionlistBean.setUserId(MchId);
			getchildselectionconditionlistBean.setSubAgentIdList(Arrays.asList(AgentId,AgentId1));
			getchildselectionconditionlistCall.setData(getchildselectionconditionlistBean);
			getchildselectionconditionlistCall.callService();			
			Logger.verifyEquals("200", getchildselectionconditionlistCall.getString("code"), "验证code");
			
			
			JsonArray scopeList = getchildselectionconditionlistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("scopeList");
			Logger.verifyEquals(AgentId, scopeList.get(0).getAsJsonObject().get("agentId").getAsInt(), "验证代理编号1");
			Logger.verifyEquals(1, scopeList.get(0).getAsJsonObject().get("scope").getAsInt(), "验证规则");
			Logger.verifyEquals(AgentId1, scopeList.get(1).getAsJsonObject().get("agentId").getAsInt(), "验证代理编号1");
			Logger.verifyEquals(0, scopeList.get(1).getAsJsonObject().get("scope").getAsInt(), "验证规则");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}